<%@page pageEncoding="utf-8" contentType="text/html; charset=utf-8"%>
<%@taglib prefix="s" uri="strutsTags"%>

<div id="dlgCalendarShow" style="width: 350px;"
	class="prompt_div_inline">
	<form id="lcContent" name="lcContent" action="#" method="POST"
		enctype="multipart/form-data">
		<s:hidden id="lc.lcId" name="lc.lcId" />
		<table width="100%">
			<tr>
				<td>
					日期:
				</td>
				<td>
					<s:textfield id="lc_lcDate" name="lc.lcDate" required="true"
						size="10" maxlength="10" />
					<img onclick="WdatePicker({el:'lc_lcDate'})" class="dateimg"
						src="resource/js/My97DatePicker/skin/datePicker.gif">
				</td>
			</tr>
			<tr>
				<td>
					种类:
				</td>
				<td>
					<s:select id="lc.lcSign" name="lc.lcSign" list="typeList"
						listKey="lcSign" listValue="signName" />
				</td>
			</tr>
			<tr>
				<td>
					所属地区:
				</td>
				<td>
					<s:select id="lc.lcLocationNo.id" name="lc.lcLocationNo.id"
						list="locationList" listKey="id" listValue="locationName"
						emptyOption="false" />
				</td>
			</tr>
			<tr>
				<td>
					日历描述:
				</td>
				<td>
					<s:textarea id="lc.lcDateDesc" cols="30" rows="3"
						onkeyup="if(this.value.length>64){this.value=this.value.substring(0, 64);}" />
				</td>
			</tr>
			<tr>
				<td colspan="2" align="center">
					<strong class="errorMessage"><label id="errorinfo"></label>
					</strong>
				</td>
			</tr>
			<tr>
				<td colspan="2" class="prompt_div_bottom">
					<input id="submited" class="button" type="button"
						onclick="submitDo();" value="提交">
					<input id="reseted" class="button" type="button"
						onclick="canceled();" value="取消">
				</td>
			</tr>
		</table>
	</form>
</div>

<script type="text/javascript" language="javascript">
	//添加日历
	function addLC() {
		ShowLC(-1, 'add');
	}

	//修改日历
	function updateLeaveC() {
		if (editObj == null || editObj.id.length == 0) {
			alert('没有选中任何日历!');
			return;
		}
		ShowLC(editObj.id, 'update'); //editObj.id 当前行
	}

	//删除日历 
	function deleteLeaveC() {
		if (editObj == null) {
			alert('没有选中任何日历!');
			return;
		}
		ShowLC(editObj.id, 'del');
	}

	//invoke_drag("lcshowhead","lcshow");
	var operartion; //操作类型(公用变量)
	var optID; //当前行Id

	//提交(Dialog提交按钮)
	function submitDo() {
		$('#submited').attr("disabled", true);
		if (operartion != 'del' && !hrm.common.isDate($('#lc_lcDate').val())) { //调common方法 operartion!='del' && $('#lc_lcDate').val().length!=10
			alert("日期输入不正确，格式应如：2009-08, 请重新输入！");
			$('#submited').attr("disabled", false);
			return;
		}
		if (operartion != 'del'
				&& $('#lc_lcDate').val().indexOf($('#yearSelect').val()) != 0) { //$('lc.lcDate').value.indexOf($('yearSelect').value)!=0
			alert("输入日期与当前年限不符！");
			$('#submited').attr("disabled", false);
			return;
		}
		if (operartion == 'add') {
			var location = {
				'id' :DWRUtil.getValue('lc.lcLocationNo.id')
			};
			var lc = {
				'lcId' :0,
				'lcSign' :DWRUtil.getValue('lc.lcSign'),
				'lcDate' :getDateFromFormat($('#lc_lcDate').val(), 'yyyy-MM-dd'),
				'lcLocationNo' :location,
				'lcDateDesc' :DWRUtil.getValue('lc.lcDateDesc')
			};
			LCMNG.insertLeavecalendar(lc, addupdate_callback);
		} else if (operartion == 'update') {
			var year = getDateFromFormat($('#lc_lcDate').val(), 'yyyy');

			var location = {
				'id' :DWRUtil.getValue('lc.lcLocationNo.id')
			};
			var lc = {
				'lcId' :DWRUtil.getValue('lc.lcId'),
				'lcDate' :getDateFromFormat($('#lc_lcDate').val(), 'yyyy-MM-dd'),
				'lcSign' :DWRUtil.getValue('lc.lcSign'),
				'lcLocationNo' :location,
				'lcDateDesc' :DWRUtil.getValue('lc.lcDateDesc')
			};
			LCMNG.updateLeavecalendar(lc, addupdate_callback);
		} else if (operartion == 'del') {
			LCMNG.delLeavecalendar(optID, addupdate_callback);
		}
		function addupdate_callback(msg) {
			if (msg == 'suc') {
				//Element.hide('dlgCalendarShow');
				hrm.common.closeDialog('dlgCalendarShow');
				$('#infoMeg').val('操作成功。');
				$('#actionSrc').get(0).submit();
				return;
			}
			if (operartion == 'del') {
				alert(msg);
			} else {
				DWRUtil.setValue('errorinfo', msg);
				//$('submited').disabled=false;
				$('#submited').attr("disabled", false);
			}
		}
	}

	//关闭(取消按钮)
	function canceled() {
		//Element.hide('dlgCalendarShow');
		hrm.common.closeDialog('dlgCalendarShow');
	}

	//显示日历(增删改公用)
	function ShowLC(varID, varOpt) { //当前行id与操作类型
		operartion = varOpt;
		optID = varID;
		if (operartion == 'del') {
			if (confirm("您确定要删除选中日历？")) {
				submitDo();
			}
			return;
		}
		if (operartion == 'update') {
			LCMNG.loadLeavecalendar(optID, showlc_callback);
			DWRUtil.setValue('errorinfo', '');
		} else if (operartion == 'add') {
			//$('dlgCalendarShow').style.display='inline';
			//document.getElementById('dlgCalendarShow').style.display='block';
			$('#dlgCalendarShow').dialog("option", "title", "日历信息显示");
			hrm.common.openDialog('dlgCalendarShow');
			DWRUtil.setValue('lc.lcId', '');
			DWRUtil.setValue('lc.lcDate', '');
			DWRUtil.setValue('lc.lcDateDesc', '');
			DWRUtil.setValue('lc.lcLocationNo.id', '');
			DWRUtil.setValue('lc.lcSign', '');
			DWRUtil.setValue('errorinfo', '');
		}
		function showlc_callback(lc) {
			if (lc == null) {
				alert("您无权执行此操作，请重新登陆！");
				return;
			}
			//$('dlgCalendarShow').style.display='inline';
			//document.getElementById('dlgCalendarShow').style.display='block';
			$('#dlgCalendarShow').dialog("option", "title", "日历信息显示");
			hrm.common.openDialog('dlgCalendarShow');
			DWRUtil.setValue('lc.lcId', lc.lcId);
			DWRUtil.setValue('lc.lcDate', lc.lcDate.toHRMDateString()); //改掉公共方法lc.lcDate.format('yyyy-MM-dd')
			DWRUtil.setValue('lc.lcDateDesc', lc.lcDateDesc);
			if (lc.lcLocationNo != null) {
				DWRUtil.setValue('lc.lcLocationNo.id', lc.lcLocationNo.id);
			} else {
				DWRUtil.setValue('lc.lcLocationNo.id', 'all');
			}
			DWRUtil.setValue('lc.lcSign', lc.lcSign);
		}
	}

	hrm.common.initDialog('dlgCalendarShow');
</script>